// pages/news/news.js
const app = getApp()
var that = this;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    title: '',
    reward: '',
    district: '',
    address: '',
    workTime: '',
    pageviews: '',
    createTime: '',
    requirements: '',
    contact: '' ,
    telephone: '',
    workContent: '',

    // src: '/res/img_share2.jpg'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var pageSize = 1;
    // console.log(options.id)
    wx.showNavigationBarLoading() //在标题栏中显示加载
    wx.request({
      url: app.globalData.urlPath + 'getPartTimeById.action',
      data: {
        id: options.id,
      },
      success: function (res) {
        var data = res.data;
        var newCreateTime = that.timestampToTime(data.createTime);
        that.setData({
          id: data.id,
          title: data.title,
          reward: data.reward,
          createTime: newCreateTime,
          district: data.district,
          address: data.address,
          workTime: data.workTime,
          pageviews: data.pageviews,
          requirements: data.requirements,
          contact: data.contact,
          telephone: data.telephone,
          workContent: data.workContent,
        })
      }
    })
  },

  timestampToTime: function (timestamp) {
    var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var D = date.getDate() + ' ';
    // var h = date.getHours() + ':';
    // var m = date.getMinutes() + ':';
    // var s = date.getSeconds();
    return Y + M + D;
  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    if(res.from === 'button'){
      console.log(res.target, res)
    }
    return{
      title: '来自STULive的兼职分享',
      path: 'pages/parttime/detail',
      imageUrl:'images/parttime/img_share2.png'
    }
  },

  // 一键复制事件
  copyBtn: function (e) {
    var that = this;
    wx.setClipboardData({
      //准备复制的数据
      data: that.data.telephone,
      success: function (res) {
        wx.showToast({
          title: '复制号码成功',
        });
      }
    });
  },

})